#include "wxscolourpickerctrl.h"

#include <wx/clrpicker.h>

namespace {
  wxsRegisterItem<wxsColourPickerCtrl> Reg( _T( "ColourPickerCtrl" ), _T( "颜色控件" ), wxsTWidget, _T( "对话框" ), 140 );
  WXS_ST_BEGIN( wxsColourPickerCtrlStyles, _T( "" ) )
  WXS_ST_CATEGORY( "wxColourPickerCtrl" )
  WXS_ST( wxCLRP_SHOW_LABEL )
  WXS_ST( wxCLRP_USE_TEXTCTRL )
  WXS_ST_END()
  WXS_EV_BEGIN( wxsColourPickerCtrlEvents )
  WXS_EVI( EVT_COLOURPICKER_CHANGED, wxEVT_COMMAND_COLOURPICKER_CHANGED, wxColourPickerEvent, ColourChanged )
  WXS_EV_END()
}

wxsColourPickerCtrl::wxsColourPickerCtrl( wxsItemResData* Data ):
  wxsWidget(
    Data,
    &Reg.Info,
    wxsColourPickerCtrlEvents,
    wxsColourPickerCtrlStyles ),
  m_cdColour( *wxBLACK ) {}


void wxsColourPickerCtrl::OnBuildCreatingCode() {
  switch( GetLanguage() ) {
    case wxsCPP: {
      AddHeader( _T( "<wx/clrpicker.h>" ), GetInfo().ClassName, 0 );
      wxString ss = m_cdColour.BuildCode( GetCoderContext() );
      Codef( _T( "%C(%W, %I, %s, %P, %S, %T, %V, %N);\n" ), ss.wx_str() );
      BuildSetupWindowCode();
      return;
    }
    case wxsUnknownLanguage:
    default: {
      wxsCodeMarks::Unknown( _T( "wxsColourPickerCtrl::OnBuildCreatingCode" ), GetLanguage() );
    }
  }
}


wxObject* wxsColourPickerCtrl::OnBuildPreview( wxWindow* Parent, long Flags ) {
  wxColourPickerCtrl* Preview;
  wxColour clr = m_cdColour.GetColour();
  if( clr.IsOk() ) {
    Preview = new wxColourPickerCtrl( Parent, GetId(), clr, Pos( Parent ), Size( Parent ), Style() );
  } else {
    Preview = new wxColourPickerCtrl( Parent, GetId(), *wxBLACK, Pos( Parent ), Size( Parent ), Style() );
  }
  return SetupWindow( Preview, Flags );
}


void wxsColourPickerCtrl::OnEnumWidgetProperties( M_Code_unused long Flags ) {
  WXS_COLOUR( wxsColourPickerCtrl, m_cdColour, _T( "Colour" ), _T( "colour" ) );
}
